<template>
  <el-dialog
    width="22%"
    :title="$t('message.universal.title')"
    :model-value="showColor"
    @close="close"
  >
    <div>
      <h4>{{ $t('message.theme.themeColorChange') }}</h4>
      <el-color-picker v-model="color" :predefine="predefineColor" />
    </div>
    <template #footer>
      <el-button @click="close">{{ $t('message.universal.cancel') }}</el-button>
      <el-button @click="confirm" type="primary">
        {{ $t('message.universal.confirm') }}
      </el-button>
    </template>
  </el-dialog>
</template>
<script setup>
import { ref, defineProps, defineEmits } from 'vue'
import { useStore } from 'vuex'
import { createNewStyle } from '@/utils/theme.js'
const store = useStore()
const color = ref(store.getters.mainColor)
const predefineColor = [
  '#ff4500',
  '#ff8c00',
  '#ffd700',
  '#90ee90',
  '#00ced1',
  '#1e90ff',
  '#c71585',
  'rgba(255, 69, 0, 0.68)',
  'rgb(255, 120, 0)',
  'hsv(51, 100, 98)',
  'hsva(120, 40, 94, 0.5)',
  'hsl(181, 100%, 37%)',
  'hsla(209, 100%, 56%, 0.73)',
  '#c7158577'
]
defineProps({
  showColor: {
    type: Boolean,
    required: true
  }
})
const emits = defineEmits(['update:showColor'])
const close = () => {
  emits('update:showColor', false)
}
const confirm = async () => {
  store.commit('theme/setMainColor', color.value)
  await createNewStyle(color.value)
  close()
}
</script>
<style></style>
